const Mock = require("mockjs");
const Random=Mock.Random;
let classObj = {
    list: [
        { id: 1, name: "wbs22082前端班" },
        { id: 2, name: "wbs22072前端班" },
        { id: 3, name: "wbs22071java班" },
        { id: 4, name: "wbs22083UI班" },
        { id: 5, name: "wbs22054java班" }

    ]
};

let stuObj = {
    list: [
        { id: 1001, name: "花花", link: 15856987854, cname: "wbs22082前端班" },
        { id: 1002, name: "紫儿", link: 15856987851, cname: "wbs22054java班" },
        { id: 1003, name: "永强", link: 15856987852, cname: "wbs22082前端班" },
        { id: 1004, name: "涵儿", link: 15856987857, cname: "wbs22083UI班" },
        { id: 10055, name: "鱼儿", link: 15856987859, cname: "wbs22071java班" },

    ]
};


/* 
mockjs的规则:
    属性名|规则 
*/
let classData = {

    //表示是数组中有20条数据
    'list|20': [{
        'id|+1':1,//id的值每次加1
        'name|+1':["wbs22082前端班","wbs22072前端班","wbs22071java班","wbs22083UI班","wbs22054java班"]//从数组中顺序选取 1 个元素，作为最终值。

    }]
};

let stuData = {

    //表示是数组中有20条数据
    'list|10': [{
        'id|+1':1001,//id的值每次加1
        'name|+1':'@cname',//随机出的中文名字
        'link|+1':13800000000,
        'img':Random.image('160x160',Random.color()),
        'cname|+1':["wbs22082前端班","wbs22072前端班","wbs22071java班","wbs22083UI班","wbs22054java班"]

    }]
};

function loadClassList(){
    return Mock.mock(classData);
}
function loadStudentList(){
    return Mock.mock(stuData);
}

let objs = [
    {
        objId: 1,
        name: "阿花",
        hobby: "吃饭",
        address: "南京"
    },
    {
        objId: 2,
        name: "阿力",
        hobby: "唱歌",
        address: "北京"
    },
    {
        objId: 3,
        name: "阿飞",
        hobby: "跳舞",
        address: "上海"
    }
];


const loginFun = function (user = {}) {
    if (user.username == "admin" && user.password == "123456") {
        return {
            username: "admin",
            password: "123456"
        }
    } else {
        return null;
    }
};


module.exports = {
    loginFun,
    classObj,
    stuObj,
    objs,
    loadClassList,
    loadStudentList
};